package com.wisely.highlight_springmvc4;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

/**
 * web 配置
 * @author devin
 */
public class WebInitializer implements WebApplicationInitializer{

	@Override
	public void onStartup(ServletContext servletContext) throws ServletException {
	/*		AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
			ctx.register(MyMvcConfig.class);
			ctx.refresh();
			ctx.setServletContext(servletContext);
			Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx));
			servlet.addMapping("/");
			servlet.setLoadOnStartup(1);*/
		AnnotationConfigWebApplicationContext dispatcherContext =new AnnotationConfigWebApplicationContext();
		  dispatcherContext.register(DispatcherConfig.class); 
		  dispatcherContext.setServletContext(servletContext);
		         //Register and map the dispatcher servlet
		        ServletRegistration.Dynamic dispatcher =servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
		        dispatcher.setLoadOnStartup(1);
		        dispatcher.addMapping("*.html");


			
	}

}
